package cloud.xiangyixiang.www.spring.boot.java.basics.utils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * <p>
 * Socket客户端上传文件
 * </p>
 *
 * @author weixin
 * @date 2023/9/4 17:40
 */
public class IoSocketClientUtil {

    /**
     * 根路径
     */
    private static final String ROOT_PATH = System.getProperty("user.dir") + "/spring-boot-java-basics/src/main/resources/";

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 9999);
        InputStream in = socket.getInputStream();
        byte[] bytes = new byte[1000];
        int len;
        OutputStream out = new FileOutputStream(ROOT_PATH + "jquery.js");
        while ((len = in.read(bytes)) != -1){
            out.write(bytes,0,len);
        }
        System.out.println("下载成功！");
        socket.close();
        out.close();
    }

}
